import time

from selenium.webdriver.common.by import By

from base_config import HOUSE_HOST
from pages.base_page import BasePage
from pages.elements import Elements
from pages.house_index_page import HouseIndexPage
from pages.login_sucess_page import LoginSuccessPage
from utils.log_manager import my_logger

class HouseLoginPage(BasePage):
    url = HOUSE_HOST + '/login'
    '''
    普通用户登录
    '''
    def putong_login(self,phone,passwd):
        self.input_data(Elements.HOUSE_USER_NAME_ELE,phone)
        self.input_data(Elements.HOUSE_PASSWORD_ELE, passwd)
        self.click_element(Elements.HOUSE_PUTONG_USER_TYPE)
        self.click_element(Elements.HOUSE_LOGIN_BTN_ELE)
        return HouseIndexPage()
    '''
    房东登录
    '''
    def fangdong_login(self,phone,passwd):
        self.input_data(Elements.HOUSE_USER_NAME_ELE, phone)
        self.input_data(Elements.HOUSE_PASSWORD_ELE, passwd)
        self.click_element(Elements.HOUSE_FANGDONG_USER_TYPE)
        self.click_element(Elements.HOUSE_LOGIN_BTN_ELE)
        return HouseIndexPage()

    def is_login_success(self):
        time.sleep(1)
        try:
            current_url = self.driver.current_url
            my_logger.logger.info("登录后跳转的地址:{}",current_url)
            if 'index' in current_url:
                return True
        except:
            return False
        return False





